package net.wang.concurrency.test.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

@Slf4j
public class FutureTaskExample {


    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executorService = Executors.newCachedThreadPool();
        FutureTask<String> futureTask = new FutureTask<>(() -> {
            log.info("doing in callable ... ");
            Thread.sleep(5000);
            return "Done !";
        });
        executorService.submit(futureTask);
        log.info("doing in main ...");
        Thread.sleep(1000);
        String res = futureTask.get();
        log.info("res : {} ", res);  //5秒后输出
        executorService.shutdown();
    }
}
